package com.six.work.mapper;

import com.six.work.entity.Post;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface PostMapper {
    @Select("select * from post;")
    List<Post> findAllPost();

    @Select("SELECT * FROM it.post join it.company on post.company_id=company.company_id where applicant_id=#{applicant_id} order by resume_post_id;")
    List<Post> findPostByAppId(Integer applicant_id);

    @Select("select * from it.post join it.company on post.company_id=company.company_id join it.resume on resume.applicant_id=post.applicant_id join it.position on post.position_id=position.position_id where resume_post_id=#{resume_post_id};")
    List<Post> findPostItem(Integer resume_post_id);

    //今日新增
    @Select("select count(*) as TodaysumPost from post where date(create_time) = curdate();")
    Integer FindTodayCom();

    //本月新增
    @Select("select count(*) as MonthsumPost from post where date_format(create_time,'%Y-%m')=date_format(now(),'%Y-%m')")
    Integer FindMonthCom();

    //插入数据到post表 求职者对公司投递简历
    @Insert("INSERT INTO post (`applicant_id`, `position_id`, `company_id`) VALUES (#{applicant_id},#{position_id},#{company_id})")
    Integer insertPost(Post post);


    //企业查看简历以后，修改状态为已查看
    @Update("UPDATE post SET `resume_state` = '已查看' \n" +
            "WHERE (resume_post_id = #{resume_post_id})\n")
    String updatePostState(Integer resume_post_id);

    //Pass
    @Update("UPDATE post SET `resume_state` = '不好意思，您的简历没通过！' \n" +
            "WHERE (resume_post_id = #{resume_post_id})\n")
    String Reject(Integer resume_post_id);

    //收下简历
    @Update("UPDATE post SET `resume_state` = '恭喜您，简历通过，请等待公司联系！' \n" +
            "WHERE (resume_post_id = #{resume_post_id})\n")
    String Received(Integer resume_post_id);

    //后台简历
    @Select("select * from it.post join it.company on post.company_id=company.company_id join it.resume on resume.applicant_id=post.applicant_id join it.position on post.position_id=position.position_id ")
    List<Post> findResume();

}
